define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'ord.order/index',
        add_url: 'ord.order/add',
        edit_url: 'ord.order/edit',
        delete_url: 'ord.order/delete',
        export_url: 'ord.order/export',
        modify_url: 'ord.order/modify',
        change_information: 'ord.order/change_information',
        ord_detail: 'ord.order/ord_detail',
        cancel_order: 'ord.order/cancel_order',
        order_refuse: 'ord.order/order_refuse',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar: ['refresh',
                    [{
                        text: '新建订单',
                        url: init.add_url,
                        method: 'open',
                        auth: 'add',
                        class: 'layui-btn layui-btn-normal layui-btn-sm',
                        icon: 'fa fa-plus ',
                        extend: 'data-full="true"',
                    }]
                ],
                cols: [[
                    {field: 'order_no', width: 200, title: '订单编号'},
                    {field: 'consignee', title: '收货人'},
                    {field: 'kahuna_name', title: '负责人'},
                    {field: 'courier_number', title: '快递单号'},
                    {field: 'order_bottom_price', title: '最低价'},
                    {field: 'amount_collected', title: '收款金额'},
                    {field: 'contact_phone', title: '联系电话',search: false},
                    {field: 'status', title: '状态', selectList: {1: '未下单',2: '待审核',3: '通过',4: '驳回',5: '预约成功',5: '已退款',6: '出库完成',7: '取消',8: '已作废'}},
                    {field: 'collection_voucher',  title: '收款凭证', search: false, templet: ea.table.image},
                  //  {field: 'img',  title: '收款凭证', search: false, templet: ea.table.image},
                    {field: 'reason', title: '驳回原因',search: false},
                    {field: 'is_cooperate', title: '是否合作快递', selectList: {1: '是',2: '否'}},
                    {title: '操作', width: 300,templet: function (d){
                        console.log(d,'d')
                            // admin_type  0超管，1业务员，2仓库员
                            if(d.admin_type == '0'){
                                return '<div >' +
                                    '<a class="layui-btn layui-btn-xs layui-btn-success" data-open="ord.order/edit?id='+d.id+'" data-full="true">编辑</a>' +
                                    '<a class="layui-btn layui-btn-xs layui-btn-success" data-open="'+init.ord_detail+'?id='+d.id+'" data-full="true">详情</a>' +
                                    '<a class="layui-btn layui-btn-danger layui-btn-xs" data-request="ord.order/cancel_order?id="'+d.id+' data-title="确定取消？">取消订单</a>'+
                                    '<a class="layui-btn layui-btn-xs layui-btn-success" data-open="'+init.change_information+'?id='+d.id+'" data-full="true">变更信息</a>'+
                                    '<a class="layui-btn layui-btn-xs layui-btn-danger" data-open="'+init.order_refuse+'?id='+d.id+'" data-full="true">驳回</a>'+
                                    '</div>'
                            }else if(d.admin_type == '1'){
                                return '<div >' +
                                    '<a class="layui-btn layui-btn-xs layui-btn-success" data-open="'+init.ord_detail+'?id='+d.id+'" data-full="true">详情</a>' +
                                    '</div>'
                            }else if(d.admin_type == '2'){
                                return '<div >' +
                                    '<a class="layui-btn layui-btn-xs layui-btn-danger" data-open="'+init.order_refuse+'?id='+d.id+'" data-full="true">驳回</a>'+
                                    '<a class="layui-btn layui-btn-xs layui-btn-success" data-open="'+init.ord_detail+'?id='+d.id+'" data-full="true">详情</a>' +
                                    '</div>'
                            }
                        }},
                   //  {title: '操作', templet: ea.table.tool,operat:[
                   //      [
                   //          {
                   //              text: '编辑',
                   //              url: init.edit_url,
                   //              method: 'open',
                   //              auth: 'edit',
                   //              class: 'layui-btn layui-btn-xs layui-btn-success',
                   //              extend: 'data-full="true"',
                   //          }
                   //     ],
                   //     [
                   //         {
                   //             text: '订单详情',
                   //             url: init.ord_detail,
                   //             method: 'open',
                   //             auth: 'edit',
                   //             class: 'layui-btn layui-btn-xs layui-btn-success',
                   //             extend: 'data-full="true"',
                   //         }
                   //    ],
                   //    [
                   //        {
                   //            text: '取消订单',
                   //            title: '确定取消订单吗？',
                   //            url: init.cancel_order,
                   //            method: 'request',
                   //            auth: 'edit',
                   //            class: 'layui-btn layui-btn-xs layui-btn-success',
                   //            extend: 'data-full="true"',
                   //        }
                   //   ],
                   //   [
                   //       {
                   //           text: '变更信息',
                   //           url: init.change_information,
                   //           method: 'open',
                   //           auth: 'edit',
                   //           class: 'layui-btn layui-btn-xs layui-btn-success',
                   //           extend: 'data-full="true"',
                   //       }
                   //    ] ,[
                   //      {
                   //         text: '驳回',
                   //         url: init.order_refuse,
                   //         method: 'open',
                   //         auth: 'edit',
                   //         class: 'layui-btn layui-btn-xs layui-btn-danger'
                   //     }
                   // ]
                   //  ]},
                ]],
            });
            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
        change_information: function () {
            ea.listen();
        },
        ord_detail: function () {
            ea.listen();
        },
        order_refuse: function () {
            ea.listen();
        }
    };
    return Controller;
});